var vampire = function(){};
vampire.dom = function(){
	var self = this;
	var utils = new vampire.utils();
	this.hasClass = function(el,text){
		var className = el.className.split(" ");
		return  className.indexOf(text)>-1?true:false;
	};
	this.addClass = function(el,text){
		var text = text.split(" ");
		text = utils.removeGap(text);
		if(el.length){
			utils.each(el,function(k,v){
				utils.each(text,function(k1,v1){
					if(!self.hasClass(v,v1)){
						v.className+=(" "+v1);					
					};
				});
			});
		}else{
			utils.each(text,function(k1,v1){
					if(!self.hasClass(el,v1)){
						el.className+=(" "+v1);					
					};
			});
		}
	};
	this.removeClass = function(el,text){
		if(el.length){
			utils.each(el,function(k,v){
				var txt = utils.removeGap(v.className.split(" "));
				utils.each(text.split(" "),function(k1,v1){
					var n = txt.indexOf(v1);
					if(n!=-1){
						txt.splice(n,1);					
					};
				});
				v.className = txt.join(" ");
			});
		}else{
				var txt = utils.removeGap(el.className.split(" "));
				utils.each(text.split(" "),function(k1,v1){
					var n = txt.indexOf(v1);
					if(n!=-1){
						txt.splice(n,1);					
					};
				});
				el.className = txt.join(" ");
		};
	};
	this.createDom = function(){
		var arg = utils.removeGap(arguments);
		if(arg.length==0){
			return ;
		};
		var ele = document.createElement(arg[0]);
		arg = arg.slice(1);
		utils.each(arg,function(k,v){
			if(typeof v=="string"){
				ele.className = v;
			}else if(typeof v==="object"&&v.nodeType ===1){
				v.appendChild(ele);	
			}else if(typeof v==="object"){
				utils.each(v,function(k1,v1){
					ele[k1] = v1;
				});
			};
		});
		return ele;
	};
};
vampire.utils = function (){
	var self = this;
	this.transferArray=function(a){
		var arr = [];var i = 0;
			self.each(a,function(k,v){
				arr[i] = v;			
				i++;
			});
		return arr;
	};
	this.each  = function (a,b){
		var i,x;
		if(typeof a!="object"){
			return ;
		};
		if(a&&a.length&&!a.nodeType){
			for(i = 0;i<a.length;i++){
				b(i,a[i],a);
				if(b.break){
					break;
				};
				if(b.continue){
						continue;
				};
			};
		}else{
			for(x in a){
				if(a.hasOwnProperty(x)){
					b(x,a[x],a);
					if(b.break){
						break;
					};
					if(b.continue){
						continue;
					};
				};
			};
		};
	};
	this.removeGap = function(a){
		var obj ;
		if(typeof a!="object"){
			return ;
		};
		if(a&&a.length&&!a.nodeType){
			obj = [];
		}else{
			obj = {};
		};
		self.each(a,function(k,v){
			if(v==""||v==undefined){
				return ;
			};
			obj[k] = v;
		});
		return obj;
	};
	this.clone = function(o){
		return JSON.parse(JSON.stringify(o));
	};
	this.deepClone = function(o){
		var obj;
		if(Array.isArray(o)){
			obj = [];
		}else{
			obj = {};
		};
		self.each(o,function(k,v){
			if(typeof v=="object"){
			 	obj[k] = self.deepClone(v);
			}else{
				obj[k] = v;
			};
		});
		return obj;
	};
};


